﻿/**
*	Group
*	@author 	Liam O'Donnell 2008-04-01
**/

package com.spikything.pants3d.objects {
	
	import com.spikything.pants3d.core.Point3D;
	import com.spikything.pants3d.core.Transformation;

	public class Group extends Point3D {
		
		public var points 	:Array; 	// List of of Point3D objects in this group
		public var rx		:Number;	// X rotation
		public var ry		:Number;	// Y rotation
		public var rz		:Number;	// Z rotation
		/*
		public var grx		:Number;	// Group X rotation
		public var gry		:Number;	// Group Y rotation
		public var grz		:Number;	// Group Z rotation
		public var arx		:Number;	// Axis X transformation
		public var ary		:Number;	// Axis Y transformation
		public var arz		:Number;	// Axis Z transformation
		*/
		public var vrx		:Number;	// X rotation speed
		public var vry		:Number;	// Y rotation speed
		public var vrz		:Number;	// Z rotation speed
		
		private var identityTransform :Transformation;
		public var axis :Point3D;

		public function Group (x:Number, y:Number, z:Number, points:Array) {
			super(x, y, z);
			rx = 0;
			ry = 0;
			rz = 0;
			//arx = 0;
			//ary = 0;
			//arz = 0;
			vrx = 0;
			vry = 0;
			vrz = 0;
			axis = new Point3D(1, 0, 0);
			this.points = points;
		}
		
		/*
		public function get rx ():Number { return grx };
		public function get ry ():Number { return gry };
		public function get rz ():Number { return grz };
		public function set rx (x:Number):void {
			var trans:Transformation = new Transformation(x, ry, rz);
			var point:Point3D = new Point3D(1, 0, 0);
			//trans.transformPoint(point, this);
			grx = rx * point.px;
			gry = ry * point.py;
			grz = rz * point.pz;
		}
		public function set ry (y:Number):void {
			var trans:Transformation = new Transformation(rx, ry, rz);
			gry = y;
		}
		public function set rz (z:Number):void {
			var trans:Transformation = new Transformation(rx, ry, rz);
			grz = z;
		}
		*/
		
		override public function update ():void {
			super.update();
			//rx += vrx;
			//ry += vry;
			//rz += vrz;
			//if (identityTransform) identityTransform.transformPoints(points, this);
			var trans:Transformation = new Transformation(rx, ry, rz);
			trans.transformPoints(points, this);
			trans.transformPoint(axis, this);
			identityTransform = new Transformation(-rx*axis.px, -ry*(1-axis.py), -rz*(1-axis.pz));
			//identityTransform = new Transformation(Math.PI*2-rx, Math.PI*2-ry, Math.PI*2-rz);
			//trace("x:" + axis.px + " y:" + axis.py + " z:" + axis.pz);
			rx = ry = rz = 0;
			px = py = pz = 0;
		}

	}
	
}